import _Dropdown from "antd/lib/dropdown";
import _Menu from "antd/lib/menu";
import _Icon from "antd/lib/icon";
import React from 'react';

var TableAction = function TableAction(props) {
  var options = props.options,
      overlayTrigger = props.overlayTrigger;

  var getSubOptionTitle = function getSubOptionTitle(option) {
    return React.createElement("a", null, typeof option.icon === 'string' ? React.createElement(_Icon, {
      type: option.icon
    }) : option.icon || null, React.createElement("span", null, option.text));
  };

  var getSubMenuItems = function getSubMenuItems(opts) {
    return opts.map(function (opt) {
      return React.createElement(_Menu.Item, {
        key: opt.key,
        onClick: opt.action
      }, getSubOptionTitle(opt));
    });
  };

  var menu = React.createElement(_Menu, null, options.map(function (option) {
    return !option.subOptions || !option.subOptions.length ? React.createElement(_Menu.Item, {
      key: option.key,
      onClick: option.action
    }, getSubOptionTitle(option)) : React.createElement(_Menu.SubMenu, {
      key: option.key,
      title: getSubOptionTitle(option)
    }, getSubMenuItems(option.subOptions || []));
  }));
  return React.createElement(_Dropdown, {
    overlay: menu,
    trigger: overlayTrigger || ['click']
  }, React.createElement("a", {
    className: "ant-dropdown-link",
    href: "#"
  }, React.createElement(_Icon, {
    type: "operation",
    style: {
      fontSize: 16,
      color: "#5a6677"
    }
  })));
};

export default TableAction;
